package homework.day01.service;


import com.tedu.InputUtil;
import homework.day01.mapper.IUserMapper;
import homework.day01.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.sql.SQLException;
import java.util.Scanner;

@Component
public class UserService {
    @Autowired
    private IUserMapper userMapper;

    public void register() {
        //方法1：
//        Scanner sc = new Scanner(System.in);
//        System.out.println("请输入注册信息：");
//        System.out.println("请输入用户名：");
//        String userName = sc.nextLine();
//        System.out.println("请输入密码：");
//        String password = sc.nextLine();
//        System.out.println("请输入昵称：");
//        String nickName = sc.nextLine();
//        System.out.println("请输入年龄：");
//        Integer age = Integer.parseInt(sc.nextLine());
//        User user = new User(null, userName, password, nickName, age);
        //方法2：
        User user = InputUtil.getInputObject(new User(),"请输入注册信息：");
        try {
            int num = userMapper.insert(user);
            System.out.println(num > 0 ? "好耶，注册成功咯！" : "啊哦，注册失败了...");
        } catch (SQLException e) {
            e.printStackTrace();
        }
//        finally {
//            sc.close();
//        }

    }

    public void login() {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入登录信息：");
        System.out.println("请输入用户名：");
        String userName = sc.nextLine();
        System.out.println("请输入密码：");
        String password = sc.nextLine();
        userMapper.select(userName, password);
    }
}
